package com.zhaopin.file;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 快速删除预上线不指向的非baselien项目 结合 FileTihuanPre 使用
 */
public class DownThePlata {

    /**
     * 目的是寻找在线的OSS的，没有召回量的，不是baseline 的
     *
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        String path = "position";
        //首先读文件
        List<String> listFile = FileUtils.readLines(new File("dir/file/filetihuan/" + path + "/position_onoss_norequest_nobaseline.txt"), Charset.defaultCharset());

        for (int i = 0; i < listFile.size(); i++) {
            //请求list 然后根据读取的文件查询策略的 id
            String s = listFile.get(i);
            String[] split = s.split(":");
            String expName = split[0];
            String tagName = split[1];
            String url1 = "https://platadmin-pre.zhaopin.com/aggr/exp/searchByName";
            System.out.println(expName + ":" + tagName + " " + i);

            String result2 = HttpRequest.post(url1)
                    .header(Header.ACCEPT, "*/*")
                    //头信息，多个头信息多次调用此方法即可
                    .header("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
                    .header("Cookie","x-zp-client-id=10329662-f75e-4496-81cf-b4e9ffccaecf; sa_jssdk_2015_platadmin-pre_zhaopin_com=%7B%22distinct_id%22%3A%22yin.peide%22%2C%22first_id%22%3A%2218a20578656639-060f4f92ff82248-19525634-2304000-18a205786578de%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThhMjA1Nzg2NTY2MzktMDYwZjRmOTJmZjgyMjQ4LTE5NTI1NjM0LTIzMDQwMDAtMThhMjA1Nzg2NTc4ZGUiLCIkaWRlbnRpdHlfbG9naW5faWQiOiJ5aW4ucGVpZGUifQ%3D%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%24identity_login_id%22%2C%22value%22%3A%22yin.peide%22%7D%7D; c=0PqHG9ex-1696669299669-fb06495728848801459023; sensorsdata2015jssdkchannel=%7B%22prop%22%3A%7B%22_sa_channel_landing_url%22%3A%22%22%7D%7D; _fmdata=Ch48pmrQDn8F7KwCfX6A8fuWNeFce%2B4mG6AK1LepJhGzE7fEEc5lcXpOqpjAWJo222hKsbHwBZlBiIJdSLC4Wg%3D%3D; 9AD585D8A7CB034A=0PqHG9ex-1696669299669-fb06495728848801459023; locationInfo_search={%22code%22:%22%22}; selectCity_search=; Hm_lvt_38ba284938d5eddca645bb5e02a02006=1708477121,1709113692; LastCity=%E5%8C%97%E4%BA%AC; LastCity%5Fid=530; 1735D64331DF397E=Ch48pmrQDn8F7KwCfX6A8fuWNeFce%2B4mG6AK1LepJhHgtFIcq5yClyTBaw47Rr9l5np0zXhpYqUEU0zTWgYv7A%3D%3D; _xid=ZGGyfKaMHGv4uZ%2BjcOaJrHEzjDtvBtWLd%2F5hc%2F1Ders%3D; sensorsdata2015jssdkcross=%7B%22%24device_id%22%3A%2217e03c767f6438-003ac901e573ac9-36657407-2304000-17e03c767f798e%22%2C%22distinct_id%22%3A%2213036161%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22first_id%22%3A%2217f10798573b7c-0f9b05b05b05b1-37677a09-2304000-17f10798574976%22%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTgyYWFlYzYxODJjMzktMGJjNzY4ZGJiMDdlZmI4LTFiNTI1NjM1LTIzMDQwMDAtMTgyYWFlYzYxODNlZWIiLCIkaWRlbnRpdHlfbG9naW5faWQiOiIxMzAzNjE2MSJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%24identity_login_id%22%2C%22value%22%3A%2213036161%22%7D%7D; PASSPORT_LOGIN_AT=28ff959eea8d4c448efd38c5db97de77; PASSPORT_OPERATOR_ID=1060265575; PASSPORT_LOGIN_NAME=yin.peide; _V=product; INNER_AUTHENTICATION=QmVhcmVyIGV5SmhiR2NpT2lKSVV6VXhNaUo5LmV5SnpkV0lpT2lJeE16QXpOakUyTVNJc0ltVjRjQ0k2TVRjeE1UWXhNelU0TTMwLlNKM0xHNy1sb3VOVWRoT2I2eUw0X3h3QVY0NVV4TXAtQ2xNdFhZZmd5U1lsRERiWGdyc19VU215OEZHbWJLcGhncmttcWVtel9KcDRnZWEzZDJxVnpB; ZPSSO_USER_EMPID=13036161; ZPSSO_USER_NAME=yin.peide; ZPSSO_USER_INFO=%7B%22empName%22%3A%22yin.peide%22%2C%22empId%22%3A%2213036161%22%2C%22branchCompanyMngDeptId%22%3A%220%22%2C%22mngDeptId%22%3A%221%22%2C%22deptId%22%3A%221%22%2C%22empRole%22%3A%220%22%2C%22salesLevel%22%3A%220%22%2C%22deptName%22%3A%22%E6%99%BA%E8%81%94%E6%8A%80%E6%9C%AF%E4%B8%AD%E5%BF%83%22%2C%22branchCompanyMngDeptName%22%3A%22%E6%80%BB%E9%83%A8%22%2C%22isLeader%22%3Afalse%7D; casgwusercred=meriA6ty_Kn7L5v7mDjVnbyuRNjtozHFIai9WlzR6PKG0MGAoQIjmuPt6k3yX-lddyrunkHZ79ifbk1118vvxhJ4sJ5HtsDZpOUOHPWjXxvevkQ4xPTAuQu-1jQHl8z9XVrit5Mr3GHoOapXSKfBN4BdSQd_B8uuvlmlVLHn2H0; crosgwusercred=VDft11Cc-z0UlW9LncCf5HpnOmkCvSW2tHqCmVRFg6uUOV_yQoCnfczbzHu-cbKqHdksH5ILCAt4RtQ1BQYgBAd84216c198d3eb29050450016bbf5e2c")
                    .form("pageNum", 1)
                    .form("pageSize", 10)
                    .form("appId", -1)
                    .form("apiId", -1)
                    .form("worldId", -1)
                    .form("name", expName)
                    //超时，毫秒
                    .timeout(200000)
                    .execute().body();
            JSONObject jsonObject = JSON.parseObject(result2);
            Object id =  JSONPath.eval(jsonObject,"$.data.list[0].id");
            System.out.println(id);

            //拿到id后进行下线操作
            String url2 = "https://platadmin-pre.zhaopin.com/aggr/release/operation";
            String result3 = HttpRequest.post(url2)
                    .header(Header.ACCEPT, "*/*")
                    //头信息，多个头信息多次调用此方法即可
                    .header("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
                    .header("Cookie","x-zp-client-id=10329662-f75e-4496-81cf-b4e9ffccaecf; sa_jssdk_2015_platadmin-pre_zhaopin_com=%7B%22distinct_id%22%3A%22yin.peide%22%2C%22first_id%22%3A%2218a20578656639-060f4f92ff82248-19525634-2304000-18a205786578de%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThhMjA1Nzg2NTY2MzktMDYwZjRmOTJmZjgyMjQ4LTE5NTI1NjM0LTIzMDQwMDAtMThhMjA1Nzg2NTc4ZGUiLCIkaWRlbnRpdHlfbG9naW5faWQiOiJ5aW4ucGVpZGUifQ%3D%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%24identity_login_id%22%2C%22value%22%3A%22yin.peide%22%7D%7D; c=0PqHG9ex-1696669299669-fb06495728848801459023; sensorsdata2015jssdkchannel=%7B%22prop%22%3A%7B%22_sa_channel_landing_url%22%3A%22%22%7D%7D; _fmdata=Ch48pmrQDn8F7KwCfX6A8fuWNeFce%2B4mG6AK1LepJhGzE7fEEc5lcXpOqpjAWJo222hKsbHwBZlBiIJdSLC4Wg%3D%3D; 9AD585D8A7CB034A=0PqHG9ex-1696669299669-fb06495728848801459023; locationInfo_search={%22code%22:%22%22}; selectCity_search=; Hm_lvt_38ba284938d5eddca645bb5e02a02006=1708477121,1709113692; LastCity=%E5%8C%97%E4%BA%AC; LastCity%5Fid=530; 1735D64331DF397E=Ch48pmrQDn8F7KwCfX6A8fuWNeFce%2B4mG6AK1LepJhHgtFIcq5yClyTBaw47Rr9l5np0zXhpYqUEU0zTWgYv7A%3D%3D; _xid=ZGGyfKaMHGv4uZ%2BjcOaJrHEzjDtvBtWLd%2F5hc%2F1Ders%3D; sensorsdata2015jssdkcross=%7B%22%24device_id%22%3A%2217e03c767f6438-003ac901e573ac9-36657407-2304000-17e03c767f798e%22%2C%22distinct_id%22%3A%2213036161%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22first_id%22%3A%2217f10798573b7c-0f9b05b05b05b1-37677a09-2304000-17f10798574976%22%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTgyYWFlYzYxODJjMzktMGJjNzY4ZGJiMDdlZmI4LTFiNTI1NjM1LTIzMDQwMDAtMTgyYWFlYzYxODNlZWIiLCIkaWRlbnRpdHlfbG9naW5faWQiOiIxMzAzNjE2MSJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%24identity_login_id%22%2C%22value%22%3A%2213036161%22%7D%7D; PASSPORT_LOGIN_AT=28ff959eea8d4c448efd38c5db97de77; PASSPORT_OPERATOR_ID=1060265575; PASSPORT_LOGIN_NAME=yin.peide; _V=product; INNER_AUTHENTICATION=QmVhcmVyIGV5SmhiR2NpT2lKSVV6VXhNaUo5LmV5SnpkV0lpT2lJeE16QXpOakUyTVNJc0ltVjRjQ0k2TVRjeE1UWXhNelU0TTMwLlNKM0xHNy1sb3VOVWRoT2I2eUw0X3h3QVY0NVV4TXAtQ2xNdFhZZmd5U1lsRERiWGdyc19VU215OEZHbWJLcGhncmttcWVtel9KcDRnZWEzZDJxVnpB; ZPSSO_USER_EMPID=13036161; ZPSSO_USER_NAME=yin.peide; ZPSSO_USER_INFO=%7B%22empName%22%3A%22yin.peide%22%2C%22empId%22%3A%2213036161%22%2C%22branchCompanyMngDeptId%22%3A%220%22%2C%22mngDeptId%22%3A%221%22%2C%22deptId%22%3A%221%22%2C%22empRole%22%3A%220%22%2C%22salesLevel%22%3A%220%22%2C%22deptName%22%3A%22%E6%99%BA%E8%81%94%E6%8A%80%E6%9C%AF%E4%B8%AD%E5%BF%83%22%2C%22branchCompanyMngDeptName%22%3A%22%E6%80%BB%E9%83%A8%22%2C%22isLeader%22%3Afalse%7D; casgwusercred=meriA6ty_Kn7L5v7mDjVnbyuRNjtozHFIai9WlzR6PKG0MGAoQIjmuPt6k3yX-lddyrunkHZ79ifbk1118vvxhJ4sJ5HtsDZpOUOHPWjXxvevkQ4xPTAuQu-1jQHl8z9XVrit5Mr3GHoOapXSKfBN4BdSQd_B8uuvlmlVLHn2H0; crosgwusercred=VDft11Cc-z0UlW9LncCf5HpnOmkCvSW2tHqCmVRFg6uUOV_yQoCnfczbzHu-cbKqHdksH5ILCAt4RtQ1BQYgBAd84216c198d3eb29050450016bbf5e2c")
                    .form("id", id)
                    .form("tag", tagName)
                    .form("env", "pre")
                    .form("version", "v1")
                    .form("type", 4)
                    //超时，毫秒
                    .timeout(200000)
                    .execute().body();

            System.out.println(expName + ": " + result3);




        }





    }
}
